﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using ProduceBasicData.Api.Application.Command.InvoiceAndReceiptManage;
using ProduceBasicData.Api.DTO.InvoiceAndReceiptDto;
using ProduceBasicData.ErrorCode;

namespace ProduceBasicData.Api.Controllers.InvoiceAndReceiptManage
{
    /// <summary>
    /// 开票控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class InvoiceController : ControllerBase
    {
        private readonly IMediator _mediator;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="mediator"></param>
        public InvoiceController(IMediator mediator)
        {
            _mediator = mediator;
        }
        /// <summary>
        /// 创建开票
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> CreateInvoice(CreateInvoiceCommand command)
        {
            return await _mediator.Send(command);
        }
        /// <summary>
        /// 获取开票列表
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult<InvoiceDto>> GetInvoiceList([FromQuery] GetInvoiceCommand command)
        {
            return await _mediator.Send(command);
        }
        /// <summary>
        /// 更新开票
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<ApiResult<int>> UpdateInvoice(UpdateInvoiceCommand command)
        {
            return await _mediator.Send(command);
        }
        /// <summary>
        /// 删除开票
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<ApiResult<int>> DeleteInvoice(DeleteInvoiceCommand command)
        {
            return await _mediator.Send(command);
        }

        /// <summary>
        /// 开票批量删除接口
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<ApiResult<int>> DeleteRangeInvoice(DeleteRangeInvoiceCommand command)
        {
            return await _mediator.Send(command);
        }
    }
}
